package test.创建和销毁对象;

/**
 * Created by chengxiaoqi1 on 2018/3/23.
 */
class MyClass3{
    //必要的参数
    private final int one;
    private final int two;
    //可选的参数
    private final int three;
    private final int four;
    private final int five;
    private final int six;

    public static class Builder{//静态内部类，也可以使用外部类，
        //必要的参数
        private final int one;
        private final int two;
        //可选的参数
        private  int three=0;
        private  int four=0;
        private  int five=0;
        private  int six=0;
        public Builder(int one,int two){
            this.one=one;
            this.two=two;
        }
        public Builder Three(int three){
            this.three=three;
            return this;//每次返回当前对象，以便后面继续调用更多初始化方法
        }
        public Builder Four(int four){
            this.four=four;
            return this;//每次返回当前对象，以便后面继续调用更多初始化方法
        }
        public Builder Five(int five){
            this.five=five;
            return this;//每次返回当前对象，以便后面继续调用更多初始化方法
        }
        public Builder Six(int six){
            this.six=six;
            return this;//每次返回当前对象，以便后面继续调用更多初始化方法
        }
        public MyClass3 build(){
            return new MyClass3(this);
        }
    }

    private MyClass3(Builder builder){
        this.one=builder.one;
        this.two=builder.two;
        this.three=builder.three;
        this.four=builder.four;
        this.five=builder.five;
        this.six=builder.six;
    }
    @Override
    public String toString(){
        return " one="+this.one+" two="+this.two+" three="+this.three+" four="+this.four+" five="+this.five+" six="+this.six;
    }
}